﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LiveCharts.Wpf;
using CartesianChart = LiveCharts.WinForms.CartesianChart;
using PieChart = LiveCharts.WinForms.PieChart;

namespace LiveCharts.WindowsFormsApp
{
    public partial class FormStartup : Form
    {
        private CartesianChart _cartesianChart;

        private Random _random;

        private PieChart _pieChart;

        public FormStartup()
        {
            InitializeComponent();

            _cartesianChart = new CartesianChart();
            tableLayoutPanel1.Controls.Add(_cartesianChart);
            _cartesianChart.Dock = DockStyle.Fill;

            _pieChart = new PieChart();
            tableLayoutPanel1.Controls.Add(_pieChart);
            _pieChart.Dock = DockStyle.Fill;

            _random = new Random();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _pieChart.Visible = false;
            _cartesianChart.Visible = true;

            _cartesianChart.Series.Clear();
            _cartesianChart.AxisX.Clear();

            _cartesianChart.Series.Add(new LineSeries { Values = new ChartValues<double> { _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300) } });
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _pieChart.Visible = false;
            _cartesianChart.Visible = true;

            _cartesianChart.Series.Clear();
            _cartesianChart.AxisX.Clear();

            _cartesianChart.Series.Add(new ColumnSeries { Values = new ChartValues<decimal> { _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300) } });
            _cartesianChart.Series.Add(new ColumnSeries { Values = new ChartValues<decimal> { _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300), _random.Next(300) } });
            _cartesianChart.AxisX.Add(new Axis { Labels = new List<string> { "一月", "二月", "三月", "四月", "五月" } });
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _cartesianChart.Visible = false;
            _pieChart.Visible = true;

            _pieChart.Series.Clear();
            _pieChart.AxisX.Clear();

            _pieChart.Series.Add(new PieSeries { Values = new ChartValues<double> { _random.Next(300) } });
            _pieChart.Series.Add(new PieSeries { Values = new ChartValues<double> { _random.Next(300) } });
            _pieChart.Series.Add(new PieSeries { Values = new ChartValues<double> { _random.Next(300) } });
            _pieChart.Series.Add(new PieSeries { Values = new ChartValues<double> { _random.Next(300) } });
            _pieChart.Series.Add(new PieSeries { Values = new ChartValues<double> { _random.Next(300) } });
        }
    }
}
